<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基于先升后降数组的二分、三分查找对比</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0;
        }
        table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
        font-size: 18px;
        text-align: left;
        background-color: #f9f9f9;
    }

    table thead tr {
        background-color: #4CAF50;
        color: white;
    }

    table th, table td {
        border: 1px solid #ddd;
        padding: 8px;
    }

    table tbody tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    table tbody tr:hover {
        background-color: #ddd;
    }
        label {
            font-size: 16px;
            margin-right: 10px;
            color: #333;
        }
        select {
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 10px;
            width: 100%;
            max-width: 200px;
        }
        .array-display {
            margin-top: 20px;
            font-size: 16px;
            color: #333;
            background-color: #f7f7f7;
            padding: 15px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            overflow-x: auto;
            display: none; /* 初始隐藏 */
        }
        .array-display span {
            display: inline-block;
            width: 60px;
            padding: 5px;
            text-align: center;
            margin-right: 5px;
            margin-bottom: 5px;
            background-color: #e4e4e4;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .container {
            max-width: 600px;
            margin: auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            margin-top: 40px;
        }
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
        form {
            margin-bottom: 30px;
        }
        form label {
            display: block;
            margin: 10px 0 5px;
            font-size: 16px;
        }
        form input {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        form button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        form button:hover {
            background-color: #45a049;
        }
        .result {
            font-size: 1.2em;
            margin-top: 20px;
            padding: 15px;
            border-radius: 8px;
            border: 1px solid #ddd;
            background-color: #f9f9f9;
            text-align: center;
        }
        .result p {
            margin: 0;
            padding: 10px;
            background-color: #e3f2fd;
            border-radius: 4px;
        }
        .result p.success {
            background-color: #e8f5e9;
            color: #388e3c;
        }
        .result p.error {
            background-color: #ffebee;
            color: #e57373;
        }
        .back-button {
            background-color: #2196F3;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            display: block;
            margin: 20px auto 0;
            transition: background-color 0.3s;
            text-decoration: none;
            text-align: center;
        }
        .back-button:hover {
            background-color: #1976D2;
        }
    </style>
</head>
<body>
    <div class="container">
        <form method="post">
            {% csrf_token %}
            <button type="submit">开始查找</button>
        </form>
        {% if result %}
            <div class="result">
            {% if result.info %}
                <p class="error">
                    查找结果: 未找到最大值或最小值<br>
                    错误信息: {{ result.info }}
                </p>
            {% else %}
                <table>
                    <thead>
                        <tr>
                            <th>查找方法</th>
                            <th>查找结果</th>
                            <th>比较次数</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>二分查找</td>
                            <td>找到最{{ res }}值 {{ result.m1 }}</td>
                            <td>{{ result.cnt1 }}</td>
                        </tr>
                        <tr>
                            <td>三分查找</td>
                            <td>找到最{{ res }}值 {{ result.m2 }}</td>
                            <td>{{ result.cnt2 }}</td>
                        </tr>
                    </tbody>
                </table>
            {% endif %}
            </div>
        {% endif %}

        <!-- 按钮和数组显示 -->
        <button id="showArrayButton" onclick="toggleArray()">显示数组</button>
        <div id="arrayContainer" class="array-display">
            {% for num in arr %}
                <td>{{ num }}</td>
            {% endfor %}
        </div>

        <script>
            function toggleArray() {
                // 获取数组容器元素
                var arrayContainer = document.getElementById("arrayContainer");

                // 切换数组容器的显示状态
                if (arrayContainer.style.display === "none" || arrayContainer.style.display === "") {
                    arrayContainer.style.display = "block"; // 显示数组
                } else {
                    arrayContainer.style.display = "none"; // 隐藏数组
                }
            }
        </script>

        <!-- 返回上一页按钮 -->
        <a href="{% url 'experiment2' %}" class="back-button">返回上一页</a>
    </div>
</body>
</html>
